<template>
	<view class="resume content">
		<!-- <telly-picker :value="value" :range="[array]" :rangekey="rangekey" placeholderText="请选择" @confirm="confirm"></telly-picker> -->
		
		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">昵称</view>
			</view>
			<view class="right flex_1 flex_r_around">
				<input type="text" placeholder="请输入昵称" v-model="info.technician_nickname">
			</view>
		</view>
		
		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">学历</view>
			</view>
			<view class="right">
				<view class="text">
					<telly-picker :value="education" :range="[educationList]" :rangekey="rangekey" placeholderText="请选择"
						@confirm="educationConfirm" title="学历" @cancel="educationCancel"></telly-picker>
				</view>
				<uni-icons type="forward" :size="18" color="#ADADAD"></uni-icons>
			</view>
		</view>

		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">民族</view>
			</view>
			<view class="right">
				<view class="text">
					<telly-picker :value="nation" :range="[nationList]" :rangekey="rangekey" placeholderText="请选择"
						@confirm="nationConfirm" title="民族" @cancel="nationCancel"></telly-picker>
				</view>
				<uni-icons type="forward" :size="18" color="#ADADAD"></uni-icons>
			</view>
		</view>
		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">星座</view>
			</view>
			<view class="right">
				<view class="text">
					<telly-picker :value="domicile" :range="[domicileList]" :rangekey="rangekey" placeholderText="请选择"
						@confirm="domicileConfirm" title="星座" @cancel="domicileCancel"></telly-picker>
				</view>
				<uni-icons type="forward" :size="18" color="#ADADAD"></uni-icons>
			</view>
		</view>

		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">籍贯</view>
			</view>
			<view class="right">
				<view class="text">
					<AddressPicker @change="cityChange" :level="3">
						<view v-if="info.constellation" style="color: #000;">{{info.constellation}}</view>
						<view v-else>
							请选择
						</view>
					</AddressPicker>
				</view>
				<uni-icons type="forward" :size="18" color="#ADADAD"></uni-icons>
			</view>
		</view>

		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">年龄</view>
			</view>
			<view class="right">
				<view class="text">
					<telly-picker :value="age" :range="[ageList]" :rangekey="rangekey" placeholderText="请选择"
						@confirm="ageConfirm" title="年龄" @cancel="ageCancel"></telly-picker>
				</view>
				<uni-icons type="forward" :size="18" color="#ADADAD"></uni-icons>
			</view>
		</view>


		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">身高</view>
			</view>
			<view class="right flex_1 flex_r_around">
				<input type="number" placeholder="请输入身高" v-model="info.height">
				<view class="text">cm</view>
			</view>
		</view>

		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">体重</view>
			</view>
			<view class="right flex_r_between">
				<input type="number" placeholder="请输入体重" v-model="info.weight">
				<view class="text">kg</view>
			</view>
		</view>

		<view class="list flex_r_between">
			<view class="left">
				<view class="circle flex_r_around">
					<text></text>
				</view>
				<view class="title">经验</view>
			</view>
			<view class="right flex_1 flex_r_around">
				<input type="number" placeholder="请输入工作经验" v-model="info.experience">
				<view class="text">年</view>
			</view>
		</view>

		<!-- <view class="textarea">
			<textarea maxlength="300" placeholder="可根据您的工作经历、擅长领域等方面进行填写。个人简介越生动详实，越多用户下单哦!"
				v-model="info.description"></textarea>
			<view class="text">300字</view>
		</view> -->

		<view class="btn" @click="submit">下一步</view>

	</view>
</template>

<script>
	import AddressPicker from "@/components/lingdang-AddressPicker/AddressPicker.vue"
	export default {
		components: {
			AddressPicker
		},
		data() {
			return {
				rangekey: ['name'],

				// 学历
				education: [],
				educationList: [

				],

				// 星座
				domicile: [],
				domicileList: [{
						name: '白羊座',
						id: 1
					},
					{
						name: '金牛座',
						id: 2
					},
					{
						name: '双子座',
						id: 3
					},
					{
						name: '巨蟹座',
						id: 4
					},
					{
						name: '狮子座',
						id: 5
					},
					{
						name: '处女座',
						id: 6
					},
					{
						name: '天秤座',
						id: 7
					},
					{
						name: '天蝎座',
						id: 8
					},
					{
						name: '射手座',
						id: 9
					},
					{
						name: '摩羯座',
						id: 10
					},
					{
						name: '水瓶座',
						id: 11
					},
					{
						name: '双鱼座',
						id: 12
					}
				],

				// 民族
				nation: [],
				nationList: [],

				// 年龄
				age: [],
				ageList: [{
						name: '85后',
						id: 1,
					},
					{
						name: '90后',
						id: 2,
					},
					{
						name: '95后',
						id: 3,
					},
					{
						name: '00后',
						id: 4,
					},
					{
						name: '05后',
						id: 5,
					}
				],

				info: {
					// 学历 体重 体重 经验 民族
					education_id: '',
					weight: '',
					height: '',
					experience: '',
					nation_id: '',
					// 自我介绍
					description: '',
					constellation: '',
					domicile: '',
					age: '',
					technician_nickname:'',
				},

				place: '',

				flag: true,
			}
		},
		methods: {
			educationConfirm(e) {
				this.info.education_id = e[0].id
			},
			educationCancel() {
				if (this.info.education_id) {
					this.educationList.forEach((item, index) => {
						if (this.info.education_id == item.id) {
							this.education = [index]
						}
					})
				} else {
					this.education = [-1]
				}
			},
			nationConfirm(e) {
				this.info.nation_id = e[0].id
			},
			nationCancel() {
				if (this.info.nation_id) {
					this.nationList.forEach((item, index) => {
						if (this.info.nation_id == item.id) {
							this.nation = [index]
						}
					})
				} else {
					this.nation = [-1]
				}
			},
			domicileConfirm(e) {
				this.info.domicile = e[0].name
			},
			domicileCancel() {
				if (this.info.domicile) {
					this.domicileList.forEach((item, index) => {
						if (this.info.domicile == item.name) {
							this.domicile = [index]
						}
					})
				} else {
					this.domicile = [-1]
				}
			},
			ageConfirm(e) {
				this.info.age = e[0].name
			},
			ageCancel() {
				if (this.info.age) {
					this.ageList.forEach((item, index) => {
						if (this.info.age == item.name) {
							this.age = [index]
						}
					})
				} else {
					this.age = [-1]
				}
			},

			changeKey(data, key_name) {
				data.forEach(obj => {
					obj['name'] = obj[key_name]; // 添加新的键值对
					delete obj[key_name]; // 删除旧的键值对
				});
			},


			getEduList() {
				let education_id = 0;
				this.request.httpTokenRequest({
					url: "index/getEduList",
					method: "get"
				}, {}).then(data => {
					if (data.code == 0) {
						this.educationList = data.data
						this.changeKey(this.educationList, 'education')
						this.educationList.forEach((item, index) => {
							if (item.name == this.info.education_id) {
								this.education = [index]
								this.info.education_id = item.id
							}
						})
					} else {
						this.$util.msg(data.msg)
					}
				}, error => {})
			},
			getNationList() {
				this.request.httpTokenRequest({
					url: "index/getNationList",
					method: "get"
				}, {}).then(data => {
					if (data.code == 0) {
						this.nationList = data.data
						this.changeKey(this.nationList, 'nation')
						this.nationList.forEach((item, index) => {
							if (item.name == this.info.nation_id) {
								this.nation = [index]
								this.info.nation_id = item.id
							}
						})
					} else {
						this.$util.msg(data.msg)
					}
				}, error => {})
			},

			submit() {
				if (!this.flag) {
					return
				}
				this.flag = false
				this.request.httpTokenRequest({
					url: "/technician.technician/saveAuthInfo",
					method: "post"
				}, this.info).then(data => {
					this.flag = true
					if (data.code == 0) {
						uni.navigateTo({
							url: '/technician/info/service'
						})
					}
				}, error => {})
			},

			cityChange(e) {
				this.info.constellation = e.data[0].name + '-' + e.data[1].name + '-' + e.data[2].name
			},
			
			getAuth(){
				let that = this
				that.request.httpTokenRequest({
					url: "technician.technician/getAuthInfo",
					method: "get"
				}, {}).then(res => {
					if (res.code == 0) {
						that.auth = res.data
						uni.setStorageSync('authInfo',that.auth)
						let auth = uni.getStorageSync('authInfo')
						that.info = {
							education_id: auth.education,
							weight: auth.weight == 0 ? '' : auth.weight,
							age: auth.age == 0 ? '' : auth.age,
							height: auth.height == 0 ? '' : auth.height,
							experience: auth.experience == 0 ? '' : auth.experience,
							nation_id: auth.nation || '',
							// description: auth.description ? auth.description : '',
							domicile: auth.domicile || '',
							constellation: auth.constellation || '',
							technician_nickname: auth.technician_nickname || '',
						}
						
						that.domicileList.forEach((item, index) => {
							if (item.name == that.info.domicile) {
								that.domicile = [index]
							}
						})
						that.ageList.forEach((item, index) => {
							if (item.name == that.info.age) {
								that.age = [index]
							}
						})
						this.getEduList()
						this.getNationList()
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},

		},
		onLoad() {
			
		},
		onShow() {
			this.getAuth()
		}
	}
</script>

<style lang="scss" scoped>
	.resume {
		padding: 30rpx 30rpx 120rpx 0;
	}

	.flex_1 {
		flex: 1;
	}

	.list {
		padding: 30rpx;
		background: #FFF;
		border-radius: 12rpx;
		margin: 15rpx 0;

		.left {
			display: flex;
			align-items: center;

			.circle {
				width: 40rpx;
				height: 40rpx;
				background: #F5F7F8;
				border-radius: 50%;
				margin-right: 10rpx;

				text {
					width: 10rpx;
					height: 10rpx;
					background: #B9D2F8;
					border-radius: 50%;
				}
			}
		}

		.right {
			display: flex;
			align-items: center;

			input {
				font-size: 28rpx;
				text-align: right;
				flex: 1;
			}

			.text {
				color: rgb(143, 143, 143);
				font-size: 28rpx;
				margin-left: 20rpx;
			}
		}
	}

	.textarea {
		min-height: 488rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		padding: 37rpx 30rpx 30rpx;

		textarea {
			font-size: 24rpx;
			color: #333;
			line-height: 33rpx;
			min-height: calc(488rpx - 33rpx);
		}

		.text {
			height: 33rpx;
			font-size: 24rpx;
			color: #ADADAD;
			line-height: 33rpx;
			text-align: right;
		}
	}

	.btn {
		width: 690rpx;
		height: 88rpx;
		background: #2E7EFA;
		border-radius: 44rpx;
		margin-top: 30rpx;
		font-size: 34rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		position: fixed;
		bottom: 10rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>